package history

type TreeNode struct {
	val      int
	children []*TreeNode
}

/**
 * @Description: 多叉树的层序遍历
 * @Keyword: 队列
 * @Author: kami
 * @Date: 2022/8/11 16:10
 **/
func bfsSearch(root *TreeNode) []int {
	var res []int
	if root == nil {
		return res
	}
	var queue = []*TreeNode{root}
	for len(queue) > 0 {
		var n = len(queue)
		var nextQueue []*TreeNode
		for i := 0; i < n; i++ {
			res = append(res, queue[i].val)
			if len(queue[i].children) > 0 {
				nextQueue = append(nextQueue, queue[i].children...)
			}
		}
		queue = nextQueue
	}
	return res
}
